package com.ruoyi.view.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.view.domain.TrendCount;
import com.ruoyi.view.service.ITrendCountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * trend_countController
 *
 * @author ruoyi
 * @date 2023-04-11
 */
@Controller
@RequestMapping("/view/trend_count")
public class TrendCountController extends BaseController
{
    private String prefix = "data-analysis/trend_count";

    @Autowired
    private ITrendCountService trendCountService;

    @RequiresPermissions("data-analysis:trend_count:view")
    @GetMapping()
    public String trend_count()
    {
        return prefix + "/trend_count";
    }

    /**
     * 查询trend_count列表
     */
//    @RequiresPermissions("data-analysis:trend_count:list")
    @CrossOrigin
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrendCount trendCount)
    {
//        startPage();
        List<TrendCount> list = trendCountService.selectTrendCountList(trendCount);
        return getDataTable(list);
    }

    /**
     * 导出trend_count列表
     */
    @RequiresPermissions("data-analysis:trend_count:export")
    @Log(title = "trend_count", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrendCount trendCount)
    {
        List<TrendCount> list = trendCountService.selectTrendCountList(trendCount);
        ExcelUtil<TrendCount> util = new ExcelUtil<TrendCount>(TrendCount.class);
        return util.exportExcel(list, "trend_count数据");
    }

    /**
     * 新增trend_count
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存trend_count
     */
    @RequiresPermissions("data-analysis:trend_count:add")
    @Log(title = "trend_count", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrendCount trendCount)
    {
        return toAjax(trendCountService.insertTrendCount(trendCount));
    }

    /**
     * 修改trend_count
     */
    @RequiresPermissions("data-analysis:trend_count:edit")
    @GetMapping("/edit/{trend}")
    public String edit(@PathVariable("trend") String trend, ModelMap mmap)
    {
        TrendCount trendCount = trendCountService.selectTrendCountByTrend(trend);
        mmap.put("trendCount", trendCount);
        return prefix + "/edit";
    }

    /**
     * 修改保存trend_count
     */
    @RequiresPermissions("data-analysis:trend_count:edit")
    @Log(title = "trend_count", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrendCount trendCount)
    {
        return toAjax(trendCountService.updateTrendCount(trendCount));
    }

    /**
     * 删除trend_count
     */
    @RequiresPermissions("data-analysis:trend_count:remove")
    @Log(title = "trend_count", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trendCountService.deleteTrendCountByTrends(ids));
    }
}
